package com.happle.gcmclient.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.happle.gcmclient.R;
import com.happle.gcmclient.obj.ConversationObj;
import com.happle.gcmclient.utility.DateTimeUtility;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Inna on 17.12.14.
 */
public class StatusDialogAdapter extends BaseAdapter{
    private String TAG = "StatusDialogAdapter.java";
    private Activity context;
    private Integer[] statusImages;
    private String[] statusTitles;
    private static LayoutInflater inflater = null;

    public StatusDialogAdapter(Activity activity,
                               Integer[] images, String[] titles) {
        context = activity;
        this.statusImages = images;
        this.statusTitles = titles;
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return statusTitles.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.status_dialog_layout_row, null);
            holder.statusImage = (ImageView) convertView
                    .findViewById(R.id.dialogStatusImage);
            holder.statusTitle = (TextView) convertView
                    .findViewById(R.id.dialogStatusText);
            convertView.setTag(holder);
        }

        String title = statusTitles[position];
        Integer image = statusImages[position];
        if (title != null) {
            holder = (ViewHolder) convertView.getTag();
            if (image != null)
                {
                    holder.statusImage.setImageResource(image);
                }
            holder.statusTitle.setText(title);

        } else {
            Log.i(TAG, "Null Object !");
        }
        return convertView;

    }

    class ViewHolder {
        TextView statusTitle;
        ImageView statusImage;
    }
}
